<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>我的购买视频</title>


    <!-- Expand styles -->
    <link href="../css/app/app.css" rel="stylesheet">
    <link href="../css/app/default.css" rel="stylesheet">
    <link href="../css/mui/mui.css" rel="stylesheet">


    <!-- Custom styles for this template -->
    <!-- <link href="../css/iOS/mobile/mobile.css" rel="stylesheet"> -->
</head>

<body>
    <!-- header -->
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
        <div class="mui-scroll">
            <div class="trade-list">

            </div>
        </div>
    </div>

    <!-- <div class="hobby-footer1 bg-transparent">
        <div class="display-flex align-items-center bot-issue">
            <img class="issue-img" src="../img/issue.png" alt="">
        </div>
    </div> -->



    <script src="../js/dsbridge.js"></script>
    <script src="../js/jquery.js"></script>
    <script src="../js/mui/mui.js"></script>
    <script src="../js/mui/mui.picker.min.js"></script>
    <script src="../js/layer.js"></script>
    <script src="../js/app/app-base.js"></script>
    <script src="../js/app/app-url.js"></script>
    <script src="../js/app/app-ajax.js"></script>

    <script>

        var page = 1;
        var limit = 10;
        var index = 0;
        //点赞数据index
        var praiseIndex = -1;
        //分享数据index
        var shareIndex = -1;
        var all_data = new Array();
        $(document).ready(function () {

            mui.init({
                pullRefresh: {
                    container: '#pullrefresh',
                    down: {
                        auto: true, // 首次进入自动加载
                        callback: pulldownRefresh
                    },
                    up: {
                        contentrefresh: '正在加载...',
                        callback: pullupRefresh
                    }
                }
            });
        });

        /**
        * 下拉刷新具体业务实现
        */
        function pulldownRefresh() {
            page = 1;
            var data = {
                userAccId: getUserId(),
                page: page,
                limit: limit
            }
            getServerData(url_getMyBuyVideosList, data);
        }

        /**
        * 上拉加载具体业务实现
        */
        function pullupRefresh() {
            page++;
            var data = {
                userAccId: getUserId(),
                page: page,
                limit: limit
            }
            getServerData(url_getMyBuyVideosList, data);
        }


        function getServerDataSuccess(url, data) {
            switch (url) {
                //详情
                case url_getMyBuyVideosList:
                    var list = data.data;
                    var html_data = "";
                    if (page == 1) {
                        index = 0;
                        all_data.length = 0;
                    }
                    if (list.length > 0) {
                        for (var i = 0; i < list.length; i++) {
                            all_data.push(list[i]);
                            html_data += '<div class="widget-body widget-default margin-b-5" id="' + index + '">' +
                                '<div class="person-info display-flex padding-b-10" id = "' + list[i].person.userAccId + '">' +
                                '<img class="farm-head" src="' + (isEmpty(list[i].person.headPortrait) ? "../img/headimg.png" : showSmallImg(list[i].person.headPortrait)) + '" alt="">' +
                                '<div class="display-flex flex-column justify-content-between margin-l-10">' +
                                '<span class="elli1 font-weight black font-16 font-weight no-margin">' + list[i].person.userName + '</span>' +
                                '<span class="gray font-12">' + list[i].createAt + '</span>' +
                                '</div>' +
                                '</div>' +
                                '<div class="margin-t-5 trade-list videoDetail" dId="' + index + '" >' +
                                '<img class=" " width="100%"  height="177px" src="' + (isEmpty(list[i].coverImg) ? "../img/headimg.png" : showSmallImg(list[i].coverImg)) + '" alt="">' +
                                '<p class=" elli1 black font-15 padding-t-15 padding-l-5 no-margin">' +
                                list[i].title + '</p>' +
                                '</div>' +
                                '<div class="display-flex justify-content-end align-items-center padding-t-6">' +
                                '<img class="farm-icon evalOper" src="../img/new-expert/info.png" alt="">' +
                                '<span class="gray font-12 padding-l-5 padding-r-10 evalOper">' + list[i].evaluationNum + '</span>' +
                                '<img class="farm-icon shareOper" src="../img/new-expert/share.png" alt="">' +
                                '<span class="gray font-12 padding-l-5 padding-r-10" shareOper>' + list[i].shareNum + '</span>' +
                                '<img class="farm-icon praiseOper praiseImg" src="../img/applaud.png" alt="">' +
                                '<span class="gray font-12 padding-l-5 praiseOper praiseNum">' + list[i].praiseNum + '</span>' +
                                '</div>' +
                                '</div>';

                            index++;
                        }
                        ;
                    }
                    if (page == 1) {
                        mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        if (list.length > 0) {
                            mui('#pullrefresh').pullRefresh().refresh(true);
                        }
                        $(".trade-list").html(html_data);
                    } else {
                        $(".trade-list").append(html_data);
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
                    }
                    break;
                case url_commonoper_operAction + '?type=praise':
                    $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/applaud.png");
                    var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
                    var praiseNum = Number($praiseNum.text()) + 1;
                    $praiseNum.text(praiseNum);
                    break;
                case url_oper_action_cancel + '?type=praise':

                    //取消点赞
                    $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/zai.png");
                    var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
                    var praiseNum = Number($praiseNum.text()) - 1;
                    if (praiseNum < 0) {
                        praiseNum = 0;
                    }
                    $praiseNum.text(praiseNum);
                    break;
            }
        }


        function getServerDataFailed(url, data) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
        }

        //详情
        mui(".mui-content").on('tap', '.videoDetail', function () {
            var detailIndex = $(this).attr("dId");
            if (all_data[detailIndex].type == 'AGRT_TECH_VIDEO') {
                //农技视频
                localStorage.setItem("video-detail-id", all_data[detailIndex].id);
                dsBridge.call("goAgriTechVideoDetail", "");
            } else if (all_data[detailIndex].type == 'SMALL_VIDEO') {
                //小视频
                dsBridge.call("smallVideo", all_data[detailIndex].id);
            }
        });


        //去个人主页
        mui(".trade-list").on('tap', '.person-info', function () {
            localStorage.setItem("person-id", $(this).attr("id"));
            dsBridge.call("goPersonInfo");
        });
        //评论
        mui(".trade-list").on('tap', '.evalOper', function () {
            var evalIndex = $(this).parents(".widget-body").attr("id");
            console.log(all_data[evalIndex].id);
            localStorage.setItem("comment-object-id", all_data[evalIndex].id);
            dsBridge.call("goEvalOper");
        });

        //点赞/取消点赞
        mui(".trade-list").on('tap', '.praiseOper', function () {
            praiseIndex = $(this).parents(".widget-body").attr("id");
            alert(all_data[praiseIndex].id);
            if ($(this).parents(".widget-body").find("img.praiseImg").attr("src") == '../img/zai.png') {
                //点赞
                var data = {
                    userId: getUserId(),
                    itemType: 19,
                    itemId: all_data[praiseIndex].id,
                    actionType: 2,
                    channel: 2
                }
                getServerData(url_commonoper_operAction + '?type=praise', data);
            } else {

                //取消点赞
                var data = {
                    userId: getUserId(),
                    itemId: all_data[praiseIndex].id,
                    actionType: 2   
                }
                getServerData(url_oper_action_cancel + '?type=praise', data);
            }

        });

        //分享
        mui(".trade-list").on('tap', '.shareOper', function () {
            shareIndex = $(this).parents(".widget-body").attr("id");
            dsBridge.call("share", all_data[shareIndex]);
        });


    </script>

</body>

</html>